package com.zhen.aikan.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhen.aikan.entity.Version;
import com.zhen.aikan.mapper.VersionMapper;
import com.zhen.aikan.service.IVersionService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author LiJiaZhen
 * @date 2023/9/22 16:13
 */
@Service
public class VersionServiceImpl extends ServiceImpl<VersionMapper, Version> implements IVersionService {
    @Override
    public Map<String, Object> getVersion() {
        Version version = baseMapper.selectOne(null);
        return BeanUtil.beanToMap(version, new HashMap<>(),
                CopyOptions.create()
                        .setIgnoreError(false)
                        .setIgnoreNullValue(false)
                        .setFieldValueEditor((fieldName, fieldValue) -> {
                            if(fieldValue == null){
                                return null;
                            }
                            return fieldValue.toString();
                        }));
    }
}
